<?php
namespace app\common\process;

class Statistics extends Base {
	protected $only = null;

	public function __construct() {
		parent::__construct();
		$this->only = loadOnly('jy\\Order');
	}
	
	//今天成交单数
	public function today_order_number() {
		$orders = $this->only->today_order();
		return count($orders);
	}

	//今日成交金额
	public function today_money() {
		$orders = $this->only->today_order();
		$total_fee = 0;
		foreach($orders as $k => $v) {
			$total_fee += $v['total_fee'];
		}
		return $total_fee;
	}

	//今日成交商品数
	public function today_product_nums() {
		$orders = $this->only->today_order();
		$orderProductModel = $this->only->getModel('jy\\OrderProduct');
		$num = 0;
		foreach($orders as $k => $v) {
			$num += $orderProductModel->where('oid', $v['id'])->sum('num');
		}
		return $num;
	}

	//今天本店成交单数
	public function today_store_order_number() {
		$store = loadOnly('tysj\\Store')->current_store();
		if(empty($store)) {
			return 0;
		}
		$orders = $this->only->today_user_order($store['id']);
		return count($orders);
	}

	//今天本店成交金额
	public function today_store_money() {
		$store = loadOnly('tysj\\Store')->current_store();
		if(empty($store)) {
			return 0;
		}
		$orders = $this->only->today_user_order($store['id']);
		$total_fee = 0;
		foreach($orders as $k => $v) {
			$total_fee += $v['total_fee'];
		}
		return $total_fee;
	}

	//今天本店成交商品数
	public function today_store_product_nums() {
		$store = loadOnly('tysj\\Store')->current_store();
		if(empty($store)) {
			return 0;
		}
		$orders = $this->only->today_user_order($store['id']);
		$orderProductModel = $this->only->getModel('jy\\OrderProduct');
		$num = 0;
		foreach($orders as $k => $v) {
			$num += $orderProductModel->where('oid', $v['id'])->sum('num');
		}
		return $num;
	}
}